#include "Dandelion.h"
#include <daisy\OgreGraphicsManager.h>
#include <daisy\EventSystem.h>
#include <daisy\System.h>
#include <OGRE\Ogre.h>
#include <daisy\NewtonPhysicsManager.h>
#include "ModelConfig.h"
#include <Branch1EventDef.h>
#pragma warning(disable:4305)
using namespace DAISY;
Dandelion::Dandelion(const std::string &name):
MovableObject(name)
{
}
Dandelion::~Dandelion(){}
void Dandelion::doEnable()
{
	using namespace Ogre;
	_sceneMgr = DAISY::OgreGraphicsManager::getInstance().getSceneManager();
	//enable update 
	enableUpdate(true);
	setChannel(DAISY::EventChannel::create().addUserChannel<1>());
	listening(getChannel());


	_node = _sceneMgr->getRootSceneNode()->createChildSceneNode("dandelion",Ogre::Vector3(5118.04, 500, 4164.13));
	_entity = _sceneMgr->createEntity("penguin.mesh");
	_node->setScale(1,1,1);
	_node->attachObject(_entity);

}

void Dandelion::doDisable()
{
	
}
void Dandelion::doFrame()
{


}
void Dandelion::doExecute(DAISY::Event * evt)
{
	if(DAISY::BRANCH1Events::equal(evt,DAISY::BRANCH1Events::AIMING))
	{
		DAISY::Event* newEvt = DAISY::EventFactory::getInstance().createEvent();
		newEvt->setSender(shared_from_this());
		newEvt->setReceiver(evt->getSender());
		newEvt->setData<Ogre::Vector3>(_node->_getDerivedPosition());
		getEventManager()->broadcasting(newEvt);
		
	}
	
}


const std::string & Branch1DandelionFactory::getTypeName() const
{
	static const std::string typeName("Dandelion");	
	return typeName;
}
Branch1DandelionFactory::pointer_type Branch1DandelionFactory::createInstance(const std::string& instanceName, parameter_type parameter)
{
	return pointer_type(new Dandelion(instanceName));
}

